package com.nioSocketCore.chapter01;

import java.nio.CharBuffer;

/**
 * @author : wushikai
 * <p>
 * date : 2022-04-29
 * 演示  capacity , limit 属性
 */
public class BufferCapacityDemo {

    public static void main(String[] args) {



        char[] charArray = new char[]{'a', 'b', 'c', 'd', 'e'};
        CharBuffer charBuffer = CharBuffer.wrap(charArray);
        System.out.println(" A capacity () =" + charBuffer.capacity() + " limit() =" + charBuffer.limit());
        charBuffer.limit(3);   // 限制 第 4 个位置不可写入
        System.out.println();
        System.out.println("B capacity () = " + charBuffer.capacity() + " limit( ) = " + charBuffer.limit());
        charBuffer.put(0, 'o'); // 0
        System.out.println(charBuffer.get(0));
        charBuffer.put(1, 'p'); // 1
        System.out.println(charBuffer.get(1));
        charBuffer.put(2, 'q'); // 2
        System.out.println(charBuffer.get(2));
        charBuffer.put(3, 'r'); // 3- 此位置是第 一 个不可读不可写的 索 引 ;  将会在这里报错
        charBuffer.put(4, 's');
        charBuffer.put(5, 't');
        charBuffer.put(6, 'u');


    }
}
